package cn.kw0501.tms.controller;


import cn.kw0501.tms.service.AdminService;
import cn.kw0501.tms.utils.JsonResult;
import cn.kw0501.tms.utils.ParmUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 系统_管理员表 前端控制器
 * </p>
 *
 * @author Aedes
 * @since 2022-11-15
 */
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    AdminService adminService;

    @PostMapping("/login/pwd")
    public JsonResult loginPwd(@RequestParam Map<String,Object> paramMap){
        String [] pa = {"phone","password"};
        String key = ParmUtil.checkParms(pa,paramMap);
        if(key!=null){
            return JsonResult.err(1001,key+"未传递");
        }
        return adminService.loginPwd(paramMap);
    }

    @PostMapping("/login/code")
    public JsonResult loginCode(@RequestParam Map<String,Object> paramMap){
        String [] pa = {"phone","code"};
        String key = ParmUtil.checkParms(pa,paramMap);
        if(key!=null){
            return JsonResult.err(1001,key+"未传递");
        }
        return adminService.loginCode(paramMap);
    }

    @PostMapping("/logout")
    public JsonResult logout(@RequestParam Map<String,Object> paramMap){
        String [] pa = {"id"};
        String key = ParmUtil.checkParms(pa,paramMap);

        if(key!=null){
            return JsonResult.err(1001,key+"未传递");
        }

        return adminService.logout(paramMap.get("id").toString());

    }


}

